package yxm.zyf.love;

import java.math.BigDecimal;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.plugin.core.config.EnablePluginRegistries;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import yxm.zyf.love.domian.PayRequestVO;
import yxm.zyf.love.service.OrderPayOperationService;
import yxm.zyf.love.service.payService;
import yxm.zyf.love.service.impl.OrderPayService;

@RestController
@SpringBootApplication //Spring Boot核心注解，用于开启自动配置
@EnablePluginRegistries({ OrderPayOperationService.class })
@Slf4j
public class DemoApplication {
    //程序可以直接在此启动

//    @Autowired
//    private JedisPool jedisPool;

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);

        PluginRegistry<OrderPayOperationService, PayRequestVO> orderPayOperationServicePluginRegistry = (PluginRegistry<OrderPayOperationService, PayRequestVO>) context
                .getBean("orderPayOperationServiceRegistry");
        PayRequestVO vo = new PayRequestVO();
        vo.setChannel("alipay");
        vo.setPhone("1231231231");
        vo.setMoney(new BigDecimal(100));
        //获取插件
        OrderPayOperationService orderPayOperationService = orderPayOperationServicePluginRegistry.getPluginFor(vo);//getPlugins();
        //发起订单支付
        String orderPay = orderPayOperationService.orderPay(vo);
        log.info("支付返回:{}", orderPay);
//        System.exit(1);
        //        CustomerService customerService=context.getBean(CustomerService.class);
        //        MobileCustomer mobileCustomer=new MobileCustomer();
        //        mobileCustomer.setTel("1231231231");
        //        mobileCustomer.setOld(true);
        //        customerService.increments(mobileCustomer,120);

    }

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置静态资源处理
        registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/").addResourceLocations("classpath:/hospitalpay");
    }

    @Autowired
    private payService payservice;

    @RequestMapping("/")
    String index() {
        return payservice.pay().toString();
    }
}